package com.ww.microrpc.netty.handler.client;

import com.ww.microrpc.netty.protocol.ResponseMessage;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

public class SendCallBackExecutorService {
    private static final ExecutorService threadPool = Executors.newCachedThreadPool();

    public static void submitCallBack(SendCallback callback, ResponseMessage response){
        if (response.getErrorMessage() != null) {
            callback.onException(new RuntimeException(response.getErrorMessage()));
        } else {
            threadPool.submit(new Runnable() {
                @Override
                public void run() {
                    callback.onSuccess(response.getResult());
                }
            });
        }
    }
}
